package com.study.component;

/**
 * @Author tanglingyu
 * @Date: 2021/04/08/ 15:20
 * @Description
 */

import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.study.dto.Tang;
import com.study.dto.User;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@AllArgsConstructor
public class Query implements GraphQLQueryResolver {

  public User getUser(String name) {
    if (name.equals("tang")) {
      return new User(1, "张三");
    }
    return new User(2, "李四");
  }

  public User getUser3(String name) {
    return new User(10, "123");
  }

  public Tang getTang() throws Exception {
    Map<String, User> map = new HashMap<String, User>() {
      {
        put("sb", new User(100, "123456"));
      }
    };
    ObjectMapper objectMapper = new ObjectMapper();
    String ss = objectMapper.writeValueAsString(map);
    Tang tang = new Tang(1, "Tang", ss);
    return tang;
  }
}
